package org.framework.lazy.cloud.network.heartbeat.server.standalone.application.impl;

import jakarta.annotation.Resource;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyNettyServerRouteApplication;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.assembler.LazyNettyServerRouteDTOAssembler;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.lazy.netty.server.route.*;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyServerRouteDTO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.server.route.LazyNettyServerRoute;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.server.route.LazyNettyServerRouteRepository;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.wu.framework.web.response.Result;

import java.util.List;
import java.util.stream.Collectors;

/**
 * describe 服务端路由
 *
 * @author Jia wei Wu
 * @date 2025/04/05 09:00 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl
 **/
@LazyApplication
public class LazyNettyServerRouteApplicationImpl implements LazyNettyServerRouteApplication {

    @Resource
    LazyNettyServerRouteRepository lazyNettyServerRouteRepository;

    /**
     * describe 新增服务端路由
     *
     * @param lazyNettyServerRouteStoryCommand 新增服务端路由
     * @return {@link Result<LazyNettyServerRoute>} 服务端路由新增后领域对象
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<LazyNettyServerRoute> story(LazyNettyServerRouteStoryCommand lazyNettyServerRouteStoryCommand) {
        LazyNettyServerRoute lazyNettyServerRoute = LazyNettyServerRouteDTOAssembler.INSTANCE.toLazyNettyServerRoute(lazyNettyServerRouteStoryCommand);
        return lazyNettyServerRouteRepository.story(lazyNettyServerRoute);
    }

    /**
     * describe 批量新增服务端路由
     *
     * @param lazyNettyServerRouteStoryCommandList 批量新增服务端路由
     * @return {@link Result<List<LazyNettyServerRoute>>} 服务端路由新增后领域对象集合
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<List<LazyNettyServerRoute>> batchStory(List<LazyNettyServerRouteStoryCommand> lazyNettyServerRouteStoryCommandList) {
        List<LazyNettyServerRoute> lazyNettyServerRouteList = lazyNettyServerRouteStoryCommandList.stream().map(LazyNettyServerRouteDTOAssembler.INSTANCE::toLazyNettyServerRoute).collect(Collectors.toList());
        return lazyNettyServerRouteRepository.batchStory(lazyNettyServerRouteList);
    }

    /**
     * describe 更新服务端路由
     *
     * @param lazyNettyServerRouteUpdateCommand 更新服务端路由
     * @return {@link Result<LazyNettyServerRoute>} 服务端路由领域对象
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<LazyNettyServerRoute> updateOne(LazyNettyServerRouteUpdateCommand lazyNettyServerRouteUpdateCommand) {
        LazyNettyServerRoute lazyNettyServerRoute = LazyNettyServerRouteDTOAssembler.INSTANCE.toLazyNettyServerRoute(lazyNettyServerRouteUpdateCommand);
        return lazyNettyServerRouteRepository.story(lazyNettyServerRoute);
    }

    /**
     * describe 查询单个服务端路由
     *
     * @param lazyNettyServerRouteQueryOneCommand 查询单个服务端路由
     * @return {@link Result<LazyNettyServerRouteDTO>} 服务端路由DTO对象
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<LazyNettyServerRouteDTO> findOne(LazyNettyServerRouteQueryOneCommand lazyNettyServerRouteQueryOneCommand) {
        LazyNettyServerRoute lazyNettyServerRoute = LazyNettyServerRouteDTOAssembler.INSTANCE.toLazyNettyServerRoute(lazyNettyServerRouteQueryOneCommand);
        return lazyNettyServerRouteRepository.findOne(lazyNettyServerRoute).convert(LazyNettyServerRouteDTOAssembler.INSTANCE::fromLazyNettyServerRoute);
    }

    /**
     * describe 查询多个服务端路由
     *
     * @param lazyNettyServerRouteQueryListCommand 查询多个服务端路由
     * @return {@link Result<List<LazyNettyServerRouteDTO>>} 服务端路由DTO对象
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<List<LazyNettyServerRouteDTO>> findList(LazyNettyServerRouteQueryListCommand lazyNettyServerRouteQueryListCommand) {
        LazyNettyServerRoute lazyNettyServerRoute = LazyNettyServerRouteDTOAssembler.INSTANCE.toLazyNettyServerRoute(lazyNettyServerRouteQueryListCommand);
        return lazyNettyServerRouteRepository.findList(lazyNettyServerRoute).convert(lazyNettyServerRoutes -> lazyNettyServerRoutes.stream().map(LazyNettyServerRouteDTOAssembler.INSTANCE::fromLazyNettyServerRoute).collect(Collectors.toList()));
    }

    /**
     * describe 分页查询多个服务端路由
     *
     * @param lazyNettyServerRouteQueryListCommand 分页查询多个服务端路由
     * @return {@link Result<LazyPage<LazyNettyServerRouteDTO>>} 分页服务端路由DTO对象
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<LazyPage<LazyNettyServerRouteDTO>> findPage(int size, int current, LazyNettyServerRouteQueryListCommand lazyNettyServerRouteQueryListCommand) {
        LazyNettyServerRoute lazyNettyServerRoute = LazyNettyServerRouteDTOAssembler.INSTANCE.toLazyNettyServerRoute(lazyNettyServerRouteQueryListCommand);
        return lazyNettyServerRouteRepository.findPage(size, current, lazyNettyServerRoute).convert(page -> page.convert(LazyNettyServerRouteDTOAssembler.INSTANCE::fromLazyNettyServerRoute));
    }

    /**
     * describe 删除服务端路由
     *
     * @param lazyNettyServerRouteRemoveCommand 删除服务端路由
     * @return {@link Result<LazyNettyServerRoute>} 服务端路由
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<LazyNettyServerRoute> remove(LazyNettyServerRouteRemoveCommand lazyNettyServerRouteRemoveCommand) {
        LazyNettyServerRoute lazyNettyServerRoute = LazyNettyServerRouteDTOAssembler.INSTANCE.toLazyNettyServerRoute(lazyNettyServerRouteRemoveCommand);
        return lazyNettyServerRouteRepository.remove(lazyNettyServerRoute);
    }

}